//
//  PersonTests.m
//  iOSCodeLearningTests
//
//  Created by TFAppleWork-Summer on 2018/3/21.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "PersonModel.h"
#import "OCMock/OCMock.h"
@interface PersonTests : XCTestCase

@end

@implementation PersonTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

// 测试没有参数的方法
- (void)testGetName{
    PersonModel *person = [[PersonModel alloc] init];
    
    //创建一个mock对象
    id classMock = OCMClassMock([PersonModel class]);
    
    OCMStub([classMock getPersonName]).andReturn(@"wcc");
    
    XCTAssertEqualObjects([classMock getPersonName], [person getPersonName ], @"值相等");

}
// 测试有参数方法
-(void)testChangeName{
    PersonModel *person  = [[PersonModel alloc] init];
    id mockClass = OCMClassMock([PersonModel class]);
    OCMStub([mockClass changeName:[OCMArg any]]).andReturn(@"ll");
    //验证getPersonName方法有没有被调用，如果没有调用则抛出异常
//    OCMVerify([mockClass getPersonName]);
    
    XCTAssertEqualObjects([mockClass changeName:[OCMArg any]], [person changeName:@"ll"]);
}

//检查参数
- (void)testArgument{
    id mockClass = OCMClassMock([PersonModel class]);
    
    // 检查参数
    OCMStub([mockClass changeName:[OCMArg checkWithBlock:^BOOL(id obj) {
        if ([obj isKindOfClass:[NSString class]]) {
            
        }else{
            // 提示错误
//            XCTAssertFalse(obj);
            obj = @"456";
        }
        NSLog(@"%@",obj);
        return YES;
    }]]);
    
    [mockClass changeName:@"ll"];
    [mockClass changeName:[OCMArg any]];
}

@end
